package com.xuetang9.t9.hotel.mapper;

import com.xuetang9.t9.hotel.beans.EFood;
import com.xuetang9.t9.hotel.mapper.condition.ICondition;
import com.xuetang9.t9.hotel.mapper.sql.impl.FoodMapperSql;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface EFoodMapper {
    @Select("select * from e_food order by id desc limit #{begin},#{size}")
    @Results({
            @Result(id = true, column = "category", property = "category"),
            @Result(column = "category", property = "foodcategory", one = @One(select = "com.xuetang9.t9.hotel.mapper.GoryMapper.queryById"))
    })
    List<EFood> queryFoodList(@Param("begin") int begin,@Param("size") int size);

    @Select("select * from e_food where clear = 0")
    @Results({
            @Result(id = true, column = "category" ,property = "category"),
            @Result(column = "category",property = "foodcategory" ,one = @One(select = "com.xuetang9.t9.hotel.mapper.GoryMapper.queryById"))
    })
    List<EFood> queryAll();

    @Select("select * from e_food where category = #{categoryId} and clear = 0")
    @Results({
            @Result(id = true, column = "category" ,property = "category"),
            @Result(column = "category",property = "foodcategory" ,one = @One(select = "com.xuetang9.t9.hotel.mapper.GoryMapper.queryById"))
    })
    List<EFood> queryByCategoryId(@Param("categoryId") long categoryId);

    @Insert("insert e_food(name, foodDescribe, price, costPrice, category, inventoryCount, picPath, len) VALUES (#{name},#{foodDescribe},#{price},#{costPrice},#{category},#{inventoryCount},#{picPath},#{len})")
    int insertFood(@Param("name")String name,@Param("foodDescribe")String desc,@Param("price") Double price,@Param("costPrice") Double costprice,@Param("category") Long category,@Param("inventoryCount") Long inventoryCount,@Param("picPath") String path,@Param("len")String len);

    @Delete("delete from e_food where id=#{id}")
    int deleteFood(@Param("id") int id);

    @Update("update e_food set name=#{name},foodDescribe=#{foodDescribe},price=#{price},costPrice=#{costPrice},category=#{category},inventoryCount=#{inventoryCount},picPath=#{picPath},len=#{len} where id=#{id}")
    int updateFood(@Param("name")String name,@Param("foodDescribe")String desc,@Param("price") Double price,@Param("costPrice") Double costprice,@Param("category") Long category,@Param("inventoryCount") Long inventoryCount,@Param("picPath") String path,@Param("len")String len,@Param("id")Long id);

    @Select("select count(0) from e_food ")
    int queryFoodCount();

    @Select("select * from e_food where id = #{id}")
    @Results({
            @Result(id = true, column = "category", property = "category"),
            @Result(column = "category", property = "foodcategory", one = @One(select = "com.xuetang9.t9.hotel.mapper.GoryMapper.queryById"))
    })
    EFood queryById(@Param("id") Integer id);

    /**
     * 根据菜品类型查询菜品
     * @param id
     * @return
     */
    @Select("SELECT * FROM e_food WHERE category = #{id}")
    List<EFood> selectByType(@Param("id") Integer id);

    /**
     * 根据菜品类型和沽清状态查询
     * @param
     * @param
     * @return
     */
    @SelectProvider(value = FoodMapperSql.class,method = "selectByAll")
    List<EFood> selectByClear(@Param("key")ICondition condition);

    /**
     * 更新操作（沽清）
     */
    @UpdateProvider(value = FoodMapperSql.class,method = "updateClear")
    int updateByClean(@Param("key")ICondition condition);

    @SelectProvider(value = FoodMapperSql.class,method = "selectByCount")
    Long selectByCount(@Param("key") ICondition condition);

    @Select("select * from e_food where id = #{id}")
    EFood selectByIdConsfood(@Param("id") Integer id);

    @Select("select id,name,foodDescribe,category,price*orderCount as sales,costPrice*orderCount as cost,orderCount from e_food;")
    @Results({
            @Result(id = true, column = "category" ,property = "category"),
            @Result(column = "category",property = "foodcategory" ,one = @One(select = "com.xuetang9.t9.hotel.mapper.GoryMapper.queryById")),
            @Result(column = "sales",property = "price"),
            @Result(column = "cost",property = "costPrice")
    })
    List<EFood> queryFoodAnalysis();

    @Select("select orderCount from e_food")
    List<Integer> queryFoodOrder();

    @Select("select name from e_food")
    List<String> queryFoodName();
}
